package com.md.api.controller;

import com.md.api.annotation.NoRepeatSubmit;
import com.md.api.common.utils.StringUtils;
import com.md.api.entity.HttpResult;
import com.md.api.entity.ShareRecord;
import com.md.api.entity.dto.ComposeQueryDto;
import com.md.api.service.ShareSevice;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Slf4j
@RequestMapping("/share")
@RestController
public class ShareController {




	@Resource
	ShareSevice shareSevice;



	//创建分享记录  访问密码
	@NoRepeatSubmit
	@RequestMapping("/saveShare")
	public HttpResult saveShare(HttpServletRequest request, @RequestBody ShareRecord shareRecord) {
		if (null==shareRecord.getShareType()){
			return HttpResult.PARAM_ERROR;
		}
		return shareSevice.saveShare(request,shareRecord);
	}

	@RequestMapping("/pictureList")
	@ResponseBody
	public HttpResult pictureList(HttpServletRequest request, @RequestBody ComposeQueryDto qto) {
		if (StringUtils.isEmpty(qto.getShareId())){
			return HttpResult.PARAM_ERROR;
		}
		return shareSevice.pictureList(request,qto);
	}

	@RequestMapping("/shareDetail")
	@ResponseBody
	public HttpResult shareDeail(HttpServletRequest request, @RequestBody ComposeQueryDto qto) {
		if (StringUtils.isEmpty(qto.getShareId())){
			return HttpResult.PARAM_ERROR;
		}
		return shareSevice.shareDeail(request,qto);
	}

	@RequestMapping("/shareCoverImg")
	@ResponseBody
	public HttpResult shareCoverImg(HttpServletRequest request, @RequestBody ComposeQueryDto qto) {
		if (StringUtils.isEmpty(qto.getShareId())){
			return HttpResult.PARAM_ERROR;
		}
		return shareSevice.shareCoverImg(request,qto);
	}

	//校驗访问密码
	@RequestMapping("/checkSecret")
	public HttpResult checkSecret(HttpServletRequest request, @RequestBody ShareRecord shareRecord) {
		if (StringUtils.isEmpty(shareRecord.getShareId())||StringUtils.isEmpty(shareRecord.getSecret())){
			return HttpResult.PARAM_ERROR;
		}
		return shareSevice.checkSecret(request,shareRecord);
	}

	@RequestMapping("/visitRecord")
	@ResponseBody
	public HttpResult visitRecord(HttpServletRequest request, @RequestBody ComposeQueryDto qto) {
		return shareSevice.visitRecord(request,qto);
	}


	@RequestMapping("/subAItimes")
	public HttpResult subAItimes(HttpServletRequest request, @RequestBody ComposeQueryDto qto) {
		if (StringUtils.isEmpty(qto.getShareId())){
			return HttpResult.PARAM_ERROR;
		}
		return shareSevice.subAItimes(request,qto.getShareId());
	}

	@RequestMapping("/subFaceTimes")
	public HttpResult subFaceTimes(HttpServletRequest request, @RequestBody ComposeQueryDto qto) {
		if (StringUtils.isEmpty(qto.getShareId())){
			return HttpResult.PARAM_ERROR;
		}
		return shareSevice.subFaceTimes(request,qto.getShareId());
	}

}
